#!/bin/bash
# init code 

# $1 project name
# $2 mode
# $3 git server address

host=`basename $1`
[ -d /cihi/code ] || mkdir -p /cihi/code
if [ ! -d /cihi/code/$host ];then
        echo "init code,please wait ... "
        cd /cihi/code && /usr/bin/git clone git://$3/$host
        if [ $? -eq 0 ];then
                echo "init code ok in /cihi/code/$host ..." 
        else
                echo "init code failed!"
                exit 1
        fi
fi
[ -z $2 ] && mode='update' || mode=$2
if [[ $mode == 'rollback' ]];then
        cd /cihi/code/$host && git reset --hard HEAD^ || exit 1
else
        cd /cihi/code/$host && git pull || exit 1
fi
